/**
 * 作者: clz
 * 日期: 2025-07-29 16:35:43
 * 备注: 联盟动态记录
 */
package com.motu.monstercity.server.game.userdata;

import com.motu.vertx.module.utility.model.BaseModel;
import com.motu.vertx.module.utility.model.Model;
import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;

public class UnionDynamicRecordModel extends BaseModel implements Model {
	public static final String LISTKEY = "union_id";
	public static final int REDIS_EXPIRE_TIME = 0;// redis过期时间
	public static final int UPDATE_DB_TYPE = UPDATE_DB_TYPE_QUEUE;// 数据入库类型 队列入库
	public static final boolean ORDER_LIST = true;// 是否需要额外的有序列表

	protected long id; // 数据库id
	protected long unionId; // 联盟id (联盟id)
	protected String msg = ""; // 动态内容
	protected String msgReplace = ""; // 动态内容替换符
	protected long addTime; // 创建时间

	public void reset() {
	}

	protected String getKey() {
		return "UnionDynamicRecord." + id;
	}

	protected String getListKey() {
		return "UnionDynamicRecord." + unionId;
	}

	protected String getListItemKey() {
		return id + "";
	}

	public void doCreate() {
		setTableId();
		insert();
	}

	public void setTableId() {
		putId(incrTableId("union_dynamic_record"));
	}

	public JsonObject insert() {
		return super.insert(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
	}

	public void delete() {
		super.delete(getKey(), id, UPDATE_DB_TYPE, 0, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
	}

	/**
	 * 根据入库类型更新
	 */
	public JsonObject update() {
		return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, 0, getAllObj(), LISTKEY, getListKey(), getListItemKey());
	}

	/**
	 * 实时入队列
	 */
	public JsonObject updateQueueNow() {
		return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, 0, getAllObj(), LISTKEY, getListKey(), getListItemKey());
	}

	public JsonObject getAllObj(){
		JsonObject obj = new JsonObject();
		obj.put("id", id); // 数据库id
		obj.put("unionId", unionId); // 联盟id (联盟id)
		obj.put("msg", msg); // 动态内容
		obj.put("msgReplace", msgReplace); // 动态内容替换符
		obj.put("addTime", addTime); // 创建时间
		return obj;
	}

	public long getId() {
		return id;
	}

	public void putId(long id) {
		if (this.id != id) {
			this.id = id;
			updateRedisHashField(getKey(), "id", this.id);
		}
	}

	public void addId(long value) {
		this.id += value;
		updateRedisHashField(getKey(), "id", this.id);
	}

	public long getUnionId() {
		return unionId;
	}

	public void putUnionId(long unionId) {
		if (this.unionId != unionId) {
			this.unionId = unionId;
			updateRedisHashField(getKey(), "unionId", this.unionId);
		}
	}

	public void addUnionId(long value) {
		this.unionId += value;
		updateRedisHashField(getKey(), "unionId", this.unionId);
	}

	public String getMsg() {
		return msg;
	}

	public void putMsg(String msg) {
		if (!this.msg.equals(msg)) {
			this.msg = msg;
			updateRedisHashField(getKey(), "msg", this.msg);
		}
	}

	public String getMsgReplace() {
		return msgReplace;
	}

	public void putMsgReplace(String msgReplace) {
		if (!this.msgReplace.equals(msgReplace)) {
			this.msgReplace = msgReplace;
			updateRedisHashField(getKey(), "msgReplace", this.msgReplace);
		}
	}

	public long getAddTime() {
		return addTime;
	}

	public void putAddTime(long addTime) {
		if (this.addTime != addTime) {
			this.addTime = addTime;
			updateRedisHashField(getKey(), "addTime", this.addTime);
		}
	}

	public void addAddTime(long value) {
		this.addTime += value;
		updateRedisHashField(getKey(), "addTime", this.addTime);
	}

}